#ifndef __UCONFIG_H__
#define __UCONFIG_H__

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "list.h"
#include "lock.h"
#include "wait.h"
#include "elog.h"

#include "cJSON.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <stdbool.h>
#include <linux/videodev2.h>

#include "ccu_common.h"

struct uconfig;

enum UCONFIG_EVENT
{
    UCONFIG_EVENT_NONE = 0,
    UCONFIG_EVENT_TEST,
    UCONFIG_EVENT_MAX,
};

typedef int32_t (*uconfig_event_notify)(struct uconfig*, int32_t, void*, void*);

struct uconfig_event_action
{
    uconfig_event_notify notify;
    void* object;
    struct uconfig_event_action* next;
};

struct uconfig_operation
{
    int32_t (*init)(struct uconfig*);
    int32_t (*release)(struct uconfig*);

    int32_t (*start)(struct uconfig*);
    int32_t (*stop)(struct uconfig*);
    
    int32_t (*default_param)(struct uconfig *);
    int32_t (*show)(struct uconfig*);
    int32_t (*load)(struct uconfig*);
    int32_t (*save)(struct uconfig*);

    int32_t (*register_notify)(struct uconfig*, int32_t, uconfig_event_notify notify, void*);
    int32_t (*unregister_notify)(struct uconfig*, int32_t, void*);
    int32_t (*trigger_notify)(struct uconfig*, int32_t, void*);
};

struct uconfig
{
    struct list_head head;
    wait_t wait;
    lock_t lock;
    lock_t notify_lock;

    int running_flag;
    pthread_t pid;
    
    const char *input_config_file;
    const char *default_config_file;
    struct uconfig_info info;

    struct uconfig_operation* op;
    struct uconfig_event_action *paction[UCONFIG_EVENT_MAX];
};

int32_t create_init_uconfig(struct uconfig** puconfig);
void release_destroy_uconfig(struct uconfig* puconfig);
        
#ifdef __cplusplus
};
#endif

#endif
